<template>
  <div>
    <div>
      <div><van-field placeholder="请输入组织缩写" label="组织名称:"  v-model="msgs"></van-field>
        <van-button @click="get_one">查询</van-button>
        <van-button>搜索</van-button>
      </div>
    </div>
    <div>
      <van-button @click="add_orgn">新增</van-button> &ensp;&ensp;&ensp;<van-button @click="exportd">导出</van-button>
      &ensp;&ensp;&ensp;&ensp;
      <van-uploader :after-read="updalod"></van-uploader>
    </div>
    <el-tree :data="list" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
<!--    新增展示按钮-->
    <van-popup v-model:show="show" :closeable="true">
      <div style="width: 400px;height: 200px;font-size: 15px;padding: 10px">
        <van-field placeholder="请输入组织名字" label="组织名称:" v-model="name"></van-field>
        <van-radio-group v-model="radio" direction="horizontal">
          &ensp;&ensp;组织类型:
          <van-radio name="1">企业</van-radio>
        </van-radio-group>
        <van-field placeholder="请输入组织缩写" label="组织缩写:"></van-field>
        <van-field placeholder="请输入组织排序" label="组织排序:" v-model="sort"></van-field>
        &ensp;&ensp;<van-button @click="reliable_orgn">确认</van-button>
      </div>
    </van-popup>
<!--    无限极分类添加-->
    <van-popup v-model:show="show_two" :closeable="true">
      <div style="width: 500px;height: 300px;font-size: 15px;padding: 10px">
        <van-field placeholder="请输入组织名字" label="组织名称:" v-model="name"></van-field>
        <van-radio-group v-model="radio" direction="horizontal">
          &ensp;&ensp;组织类型:
          <van-radio name="1">企业</van-radio>
          <van-radio name="2">部门</van-radio>
        </van-radio-group>
        <van-field placeholder="请输入组织缩写" label="组织缩写:"></van-field>
        <van-field placeholder="请输入组织排序" label="组织排序:" v-model="sort"></van-field>
        &ensp;&ensp;<van-button @click="post_orgn">确认</van-button>
      </div>

    </van-popup>
  </div>
</template>

<script>
export default {
  name: "Organization",
  data() {
    return {
      list: [],
      show: false,
      show_two: false,
      radio: 1,
      name: '',
      type: '',
      names:'',
      id:'',
      msgs:''
    }
  },
  defaultProps: {
    children: 'children',
    label: 'label'
  },
  methods: {
    get_one:function (){
      console.log(this.msgs)
      this.myaxios("http://localhost:5000/acporgn", 'get', {'msg':this.msgs})
          .then(res => {
            console.log(res)
          })
    },
    add_orgn: function () {
      this.show = true
    },
    post_orgn(){
      this.type=2
      this.myaxios("http://localhost:5000/reliable_orgn", 'post', {'id':this.id,'name': this.name, 'codtype': this.radio, 'sort': this.sort,'type':this.type})
          .then(res => {
            console.log(res)
          })
    },
    reliable_orgn() {
      this.type=1
      this.myaxios("http://localhost:5000/reliable_orgn", 'post', {'name': this.name, 'codtype': this.radio, 'sort': this.sort,'type':this.type})
          .then(res => {
            console.log(res)
          })
    },
    handleNodeClick(list) {
      console.log(list.id);
      this.id=list.id
      this.show_two=true
      this.myaxios("http://localhost:5000/reliable_orgn", 'get', {'id':list.id})
          .then(res => {
            console.log(res)
            if (res.data.code==200){
              this.names=res.data.names
            }
          })
    },
    exportd: function () {
      this.myaxios("http://localhost:5000/download", 'get', {})
          .then(res => {
            console.log(res)
          })
    },
    updalod(file) {
      console.log(file.file)
      let data = new FormData()
      data.append("file", file.file)
      const axiosInstance = this.axios.create({withCredentials: false});
      axiosInstance({
        method: "post",
        url: "http://localhost:5000/upload",
        data: data
      }).then(res => {
        console.log(res)
      })
    },
    get_data() {
      this.myaxios("http://localhost:5000/acporgn", 'get', {})
          .then(res => {
            console.log(res)
            this.list = res.data.list1
            console.log(this.list)
          })
    }
  },
  mounted() {
    this.get_data()
  }
}
</script>

<style scoped>

</style>
